//go:build linux

package idPool8Bit

import (
	"os"
	"syscall"
)

func mmapFile(fileName string, size int) ([]byte, error) {
	file, err := os.OpenFile(fileName, os.O_RDWR, 0644)
	if err != nil {
		return nil, err
	}
	// 获取文件描述符
	fd := int(file.Fd())

	// 使用系统调用进行内存映射
	data, err := syscall.Mmap(fd, 0, size, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)
	if err != nil {
		return nil, err
	}

	return data, nil
}

func munmapFile(data []byte) error {
	return syscall.Munmap(data)
}
